﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Web.Http;
using Microsoft.Practices.Unity;

namespace Epona.Domain
{
    public abstract class Entity : IEntity
    {
        private static IRepository repository;

        public static IRepository Repository
        {
            get
            {
                if (repository == null)
                {
                    repository= GlobalConfiguration.Configuration.DependencyResolver.GetService(typeof(IRepository)) as IRepository;
                }
                return repository;
            }
            set { repository = value; }
        }

        public virtual int Id { get; set; }

        public virtual bool Existed
        {
            get
            {
                if (Id == 0)
                {
                    return false;
                }
                return Repository.Exists<IEntity>(Id);
            }
        }


        public virtual bool NotExisted
        {
            get { return !Existed; }
        }
    }
}
